/*	Interactive Gravitational Simulator
	Project: IGS Visualization
	File: Visualizer.h
	Author: Mike Bantegui <mbante2@gmail.com>, Hofstra University 
	Copyright (C) 2012 - 2013 Mike Bantegui

	This file is part of the IGS software package for simulating
	the N-Body problem in real-time. This was developed as part
	of a departmental honors thesis project at Hofstra University
	in the Spring 2012 semester.

	IGS is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	IGS is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef IGS_VISUALIZER_H
#define IGS_VISUALIZER_H

#include "Application.h"
#include "FontEngine.h"
#include "Vector.h"

namespace IGS
{

class Simulator;
class Snapshot;
struct ViewNode;

class Visualizer : public Application
{
private:
	// Whether to use the free camera
	bool UseFreeCamera;
	// The position of the camera
	Vector Position;
	// The distance from the origin in bound camera mode
	double Distance;
	// The polar angle
	double Theta;
	// The azimuthal angle
	double Phi;

	// The x-coordinate of the mouse in screen coordinates
	int MouseX;
	// The y-coordinate of the mouse in screen coordinates
	int MouseY;

	// The font rendering engine
	FontEngine Fonts;

	// Whether the visualization is currently paused
	bool IsPaused;
	// Whether the simulator is updating
	bool IsUpdating;
	// Whether the tree should be drawn
	bool TreeVisible;
	// Whether the tree should be iteratively drawn
	bool IsIterativeTree;
	// The maximum nodes to draw, for iterative drawing
	unsigned MaxNodes;

	// The gravitational simulator
	std::shared_ptr<Simulator> _Simulator;
	// The step size
	double Dt;
	// The current generation number
	unsigned Generation;

	// The list of snapshots available
	std::vector<std::shared_ptr<Snapshot>> Snapshots;
	// The maximum number of snapshots to take
	unsigned long long MaxSnapshots;
	// The current snapshot
	unsigned SnapshotIndex;


public:
	Visualizer();

protected:
	bool Initialize(int argc, char **argv);
	void Cleanup();
	void Draw();
	void Keys();
	void Mouse();
	void Loop();

private:
	void SetCamera();
	void DrawParticles();
	void DrawOSD();
	void DrawTree();
	void DrawTree(std::shared_ptr<ViewNode> root, unsigned &nodeCount, unsigned depth);
};

}

#endif